package com.jd.ty.web;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import com.jd.ty.util.FileUtil;

public class UploadFileAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private File filedata;

	private String realPath;
	private String fileExt;

	public File getFileData() {
		return filedata;
	}

	public void setFileData(File filedata) {
		this.filedata = filedata;
	}

	@Override
	public String execute() throws Exception {
		if (filedata.length() == 0) {
			return SUCCESS;
		}

		String tempPath = "";
		realPath = FileUtil.generateUniqueFileName(tempPath, fileExt);
		File fileobj = new File(realPath);
		FileUtils.copyFile(filedata, fileobj);
		filedata = null;
		return SUCCESS;
	}

	public String delete() {
		File file = new File(realPath);
		file.delete();
		return SUCCESS;
	}

	public String getRealPath() {
		return realPath;
	}

	public void setRealPath(String realPath) {
		this.realPath = realPath;
	}

	public File getFiledata() {
		return filedata;
	}

	public void setFiledata(File filedata) {
		this.filedata = filedata;
	}

	public String getFileExt() {
		return fileExt;
	}

	public void setFileExt(String fileExt) {
		this.fileExt = fileExt;
	}

}
